package com.openbravo.pos.inventory;

import com.openbravo.basic.BasicException;
import com.openbravo.beans.DateUtils;
import com.openbravo.beans.JCalendarDialog;
import com.openbravo.beans.JNumberEvent;
import com.openbravo.beans.JNumberEventListener;
import com.openbravo.beans.JNumberKeys;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.LocalRes;
import com.openbravo.data.loader.SentenceExec;
import com.openbravo.data.loader.SentenceList;
import com.openbravo.format.Formats;
import com.openbravo.pos.catalog.CatalogSelector;
import com.openbravo.pos.catalog.JCatalog;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.forms.DataLogicSales;
import com.openbravo.pos.forms.DataLogicSystem;
import com.openbravo.pos.forms.JPanelView;
import com.openbravo.pos.printer.TicketParser;
import com.openbravo.pos.printer.TicketPrinterException;
import com.openbravo.pos.sales.JProductAttEdit;
import com.openbravo.pos.scanpal2.DeviceScanner;
import com.openbravo.pos.scanpal2.DeviceScannerException;
import com.openbravo.pos.scanpal2.ProductDownloaded;
import com.openbravo.pos.scripting.ScriptEngine;
import com.openbravo.pos.scripting.ScriptException;
import com.openbravo.pos.scripting.ScriptFactory;
import com.openbravo.pos.ticket.ProductInfoExt;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

public class StockManagement extends JPanel
  implements JPanelView
{
  private AppView m_App;
  private DataLogicSystem m_dlSystem;
  private DataLogicSales m_dlSales;
  private TicketParser m_TTP;
  private CatalogSelector m_cat;
  private ComboBoxValModel m_ReasonModel;
  private SentenceList m_sentlocations;
  private ComboBoxValModel m_LocationsModel;
  private ComboBoxValModel m_LocationsModelDes;
  private JInventoryLines m_invlines;
  private int NUMBER_STATE = 0;
  private int MULTIPLY = 0;
  private static int DEFAULT = 0;
  private static int ACTIVE = 1;
  private static int DECIMAL = 2;
  private JButton btnDownloadProducts;
  private JPanel catcontainer;
  private JButton jEditAttributes;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel8;
  private JNumberKeys jNumberKeys;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JPanel jPanel3;
  private JPanel jPanel4;
  private JPanel jPanel5;
  private JPanel jPanel6;
  private JTextField jTextField1;
  private JButton m_jDelete;
  private JButton m_jDown;
  private JButton m_jEnter;
  private JComboBox m_jLocation;
  private JComboBox m_jLocationDes;
  private JButton m_jUp;
  private JButton m_jbtndate;
  private JLabel m_jcodebar;
  private JTextField m_jdate;
  private JComboBox m_jreason;

  public StockManagement(AppView paramAppView)
  {
    this.m_App = paramAppView;
    this.m_dlSystem = ((DataLogicSystem)this.m_App.getBean("com.openbravo.pos.forms.DataLogicSystem"));
    this.m_dlSales = ((DataLogicSales)this.m_App.getBean("com.openbravo.pos.forms.DataLogicSales"));
    this.m_TTP = new TicketParser(this.m_App.getDeviceTicket(), this.m_dlSystem);
    initComponents();
    this.btnDownloadProducts.setEnabled(this.m_App.getDeviceScanner() != null);
    this.m_sentlocations = this.m_dlSales.getLocationsList();
    this.m_LocationsModel = new ComboBoxValModel();
    this.m_LocationsModelDes = new ComboBoxValModel();
    this.m_ReasonModel = new ComboBoxValModel();
    this.m_ReasonModel.add(MovementReason.IN_PURCHASE);
    this.m_ReasonModel.add(MovementReason.IN_REFUND);
    this.m_ReasonModel.add(MovementReason.IN_MOVEMENT);
    this.m_ReasonModel.add(MovementReason.OUT_SALE);
    this.m_ReasonModel.add(MovementReason.OUT_REFUND);
    this.m_ReasonModel.add(MovementReason.OUT_BREAK);
    this.m_ReasonModel.add(MovementReason.OUT_MOVEMENT);
    this.m_ReasonModel.add(MovementReason.OUT_CROSSING);
    this.m_jreason.setModel(this.m_ReasonModel);
    this.m_cat = new JCatalog(this.m_dlSales);
    this.m_cat.getComponent().setPreferredSize(new Dimension(0, 245));
    this.m_cat.addActionListener(new CatalogListener( ));
    this.catcontainer.add(this.m_cat.getComponent(), "Center");
    this.m_invlines = new JInventoryLines();
    this.jPanel5.add(this.m_invlines, "Center");
  }

  public String getTitle()
  {
    return AppLocal.getIntString("Menu.StockMovement");
  }

  public JComponent getComponent()
  {
    return this;
  }

  public void activate()
    throws BasicException
  {
    this.m_cat.loadCatalog();
    List localList = this.m_sentlocations.list();
    this.m_LocationsModel = new ComboBoxValModel(localList);
    this.m_jLocation.setModel(this.m_LocationsModel);
    this.m_LocationsModelDes = new ComboBoxValModel(localList);
    this.m_jLocationDes.setModel(this.m_LocationsModelDes);
    stateToInsert();
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        StockManagement.this.jTextField1.requestFocus();
      }
    });
  }

  public void stateToInsert()
  {
    this.m_jdate.setText(Formats.TIMESTAMP.formatValue(DateUtils.getTodayMinutes()));
    this.m_ReasonModel.setSelectedItem(MovementReason.IN_PURCHASE);
    this.m_LocationsModel.setSelectedKey(this.m_App.getInventoryLocation());
    this.m_LocationsModelDes.setSelectedKey(this.m_App.getInventoryLocation());
    this.m_invlines.clear();
    this.m_jcodebar.setText(null);
  }

  public boolean deactivate()
  {
    if (this.m_invlines.getCount() > 0)
    {
      int i = JOptionPane.showConfirmDialog(this, LocalRes.getIntString("message.wannasave"), LocalRes.getIntString("title.editor"), 1, 3);
      if (i == 0)
      {
        saveData();
        return true;
      }
      return i == 1;
    }
    return true;
  }

  private void addLine(ProductInfoExt paramProductInfoExt, double paramDouble1, double paramDouble2)
  {
    this.m_invlines.addLine(new InventoryLine(paramProductInfoExt, paramDouble1, paramDouble2));
  }

  private void deleteLine(int paramInt)
  {
    if (paramInt < 0)
      Toolkit.getDefaultToolkit().beep();
    else
      this.m_invlines.deleteLine(paramInt);
  }

  private void incProduct(ProductInfoExt paramProductInfoExt, double paramDouble)
  {
    MovementReason localMovementReason = (MovementReason)this.m_ReasonModel.getSelectedItem();
    addLine(paramProductInfoExt, paramDouble, localMovementReason.isInput() ? paramProductInfoExt.getPriceBuy() : paramProductInfoExt.getPriceSell());
  }

  private void incProductByCode(String paramString)
  {
    incProductByCode(paramString, 1.0D);
  }

  private void incProductByCode(String paramString, double paramDouble)
  {
    try
    {
      ProductInfoExt localProductInfoExt = this.m_dlSales.getProductInfoByCode(paramString);
      if (localProductInfoExt == null)
        Toolkit.getDefaultToolkit().beep();
      else
        incProduct(localProductInfoExt, paramDouble);
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(localBasicException);
      localMessageInf.show(this);
    }
  }

  private void addUnits(double paramDouble)
  {
    int i = this.m_invlines.getSelectedRow();
    if (i >= 0)
    {
      InventoryLine localInventoryLine = this.m_invlines.getLine(i);
      double d = localInventoryLine.getMultiply() + paramDouble;
      if (d <= 0.0D)
      {
        deleteLine(i);
      }
      else
      {
        localInventoryLine.setMultiply(localInventoryLine.getMultiply() + paramDouble);
        this.m_invlines.setLine(i, localInventoryLine);
      }
    }
  }

  private void setUnits(double paramDouble)
  {
    int i = this.m_invlines.getSelectedRow();
    if (i >= 0)
    {
      InventoryLine localInventoryLine = this.m_invlines.getLine(i);
      localInventoryLine.setMultiply(paramDouble);
      this.m_invlines.setLine(i, localInventoryLine);
    }
  }

  private void stateTransition(char paramChar)
  {
    if (paramChar == '')
    {
      this.m_jcodebar.setText(null);
      this.NUMBER_STATE = DEFAULT;
    }
    else if (paramChar == '*')
    {
      this.MULTIPLY = ACTIVE;
    }
    else if (paramChar == '+')
    {
      if ((this.MULTIPLY != DEFAULT) && (this.NUMBER_STATE != DEFAULT))
      {
        setUnits(Double.parseDouble(this.m_jcodebar.getText()));
        this.m_jcodebar.setText(null);
      }
      else if ((this.m_jcodebar.getText() == null) || (this.m_jcodebar.getText().equals("")))
      {
        addUnits(1.0D);
      }
      else
      {
        addUnits(Double.parseDouble(this.m_jcodebar.getText()));
        this.m_jcodebar.setText(null);
      }
      this.NUMBER_STATE = DEFAULT;
      this.MULTIPLY = DEFAULT;
    }
    else if (paramChar == '-')
    {
      if ((this.m_jcodebar.getText() == null) || (this.m_jcodebar.getText().equals("")))
      {
        addUnits(-1.0D);
      }
      else
      {
        addUnits(-Double.parseDouble(this.m_jcodebar.getText()));
        this.m_jcodebar.setText(null);
      }
      this.NUMBER_STATE = DEFAULT;
      this.MULTIPLY = DEFAULT;
    }
    else if (paramChar == '.')
    {
      if ((this.m_jcodebar.getText() == null) || (this.m_jcodebar.getText().equals("")))
        this.m_jcodebar.setText("0.");
      else if (this.NUMBER_STATE != DECIMAL)
        this.m_jcodebar.setText(this.m_jcodebar.getText() + paramChar);
      this.NUMBER_STATE = DECIMAL;
    }
    else if ((paramChar == ' ') || (paramChar == '='))
    {
      if (this.m_invlines.getCount() == 0)
        Toolkit.getDefaultToolkit().beep();
      else
        saveData();
    }
    else if (Character.isDigit(paramChar))
    {
      if (this.m_jcodebar.getText() == null)
        this.m_jcodebar.setText("" + paramChar);
      else
        this.m_jcodebar.setText(this.m_jcodebar.getText() + paramChar);
      if (this.NUMBER_STATE != DECIMAL)
        this.NUMBER_STATE = ACTIVE;
    }
    else
    {
      Toolkit.getDefaultToolkit().beep();
    }
  }

  private void saveData()
  {
    try
    {
      Date localDate = (Date)Formats.TIMESTAMP.parseValue(this.m_jdate.getText());
      MovementReason localObject = (MovementReason)this.m_ReasonModel.getSelectedItem();
      if (localObject == MovementReason.OUT_CROSSING)
      {
        saveData(new InventoryRecord(localDate, MovementReason.OUT_MOVEMENT, (LocationInfo)this.m_LocationsModel.getSelectedItem(), this.m_invlines.getLines()));
        saveData(new InventoryRecord(localDate, MovementReason.IN_MOVEMENT, (LocationInfo)this.m_LocationsModelDes.getSelectedItem(), this.m_invlines.getLines()));
      }
      else
      {
        saveData(new InventoryRecord(localDate, (MovementReason)localObject, (LocationInfo)this.m_LocationsModel.getSelectedItem(), this.m_invlines.getLines()));
      }
      stateToInsert();
    }
    catch (BasicException localBasicException)
    {
      Object localObject = new MessageInf(-67108864, AppLocal.getIntString("message.cannotsaveinventorydata"), localBasicException);
      ((MessageInf)localObject).show(this);
    }
  }

  private void saveData(InventoryRecord paramInventoryRecord)
    throws BasicException
  {
    SentenceExec localSentenceExec = this.m_dlSales.getStockDiaryInsert();
    for (int i = 0; i < this.m_invlines.getCount(); i++)
    {
      InventoryLine localInventoryLine = (InventoryLine)paramInventoryRecord.getLines().get(i);
      localSentenceExec.exec(new Object[] { UUID.randomUUID().toString(), paramInventoryRecord.getDate(), paramInventoryRecord.getReason().getKey(), paramInventoryRecord.getLocation().getID(), localInventoryLine.getProductID(), localInventoryLine.getProductAttSetInstId(), paramInventoryRecord.getReason().samesignum(Double.valueOf(localInventoryLine.getMultiply())), Double.valueOf(localInventoryLine.getPrice()) });
    }
    printTicket(paramInventoryRecord);
  }

  private void printTicket(InventoryRecord paramInventoryRecord)
  {
    String str = this.m_dlSystem.getResourceAsXML("Printer.Inventory");
    Object localObject;
    if (str == null)
    {
      localObject = new MessageInf(-33554432, AppLocal.getIntString("message.cannotprintticket"));
      ((MessageInf)localObject).show(this);
    }
    else
    {
      try
      {
        localObject = ScriptFactory.getScriptEngine("velocity");
        ((ScriptEngine)localObject).put("inventoryrecord", paramInventoryRecord);
        this.m_TTP.printTicket(((ScriptEngine)localObject).eval(str).toString());
      }
      catch (ScriptException localScriptException)
      {
        MessageInf localMessageInf = new MessageInf(-33554432, AppLocal.getIntString("message.cannotprintticket"), localScriptException);
        localMessageInf.show(this);
      }
      catch (TicketPrinterException localTicketPrinterException)
      {
        MessageInf localMessageInf = new MessageInf(-33554432, AppLocal.getIntString("message.cannotprintticket"), localTicketPrinterException);
        localMessageInf.show(this);
      }
    }
  }

  private void initComponents()
  {
    this.jPanel1 = new JPanel();
    this.jPanel2 = new JPanel();
    this.jNumberKeys = new JNumberKeys();
    this.jPanel4 = new JPanel();
    this.m_jEnter = new JButton();
    this.m_jcodebar = new JLabel();
    this.jTextField1 = new JTextField();
    this.jPanel6 = new JPanel();
    this.btnDownloadProducts = new JButton();
    this.jPanel3 = new JPanel();
    this.jLabel1 = new JLabel();
    this.m_jdate = new JTextField();
    this.m_jbtndate = new JButton();
    this.jLabel2 = new JLabel();
    this.m_jreason = new JComboBox();
    this.jLabel8 = new JLabel();
    this.m_jLocation = new JComboBox();
    this.m_jDelete = new JButton();
    this.m_jUp = new JButton();
    this.m_jDown = new JButton();
    this.jPanel5 = new JPanel();
    this.m_jLocationDes = new JComboBox();
    this.jEditAttributes = new JButton();
    this.catcontainer = new JPanel();
    setLayout(new BorderLayout());
    this.jPanel1.setLayout(new BorderLayout());
    this.jPanel2.setLayout(new BoxLayout(this.jPanel2, 1));
    this.jNumberKeys.addJNumberEventListener(new JNumberEventListener()
    {
      public void keyPerformed(JNumberEvent paramJNumberEvent)
      {
        StockManagement.this.jNumberKeysKeyPerformed(paramJNumberEvent);
      }
    });
    this.jPanel2.add(this.jNumberKeys);
    this.jPanel4.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.jPanel4.setLayout(new GridBagLayout());
    this.m_jEnter.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/barcode.png")));
    this.m_jEnter.setFocusPainted(false);
    this.m_jEnter.setFocusable(false);
    this.m_jEnter.setRequestFocusEnabled(false);
    this.m_jEnter.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        StockManagement.this.m_jEnterActionPerformed(paramActionEvent);
      }
    });
    GridBagConstraints localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 1;
    localGridBagConstraints.gridy = 0;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(0, 5, 0, 0);
    this.jPanel4.add(this.m_jEnter, localGridBagConstraints);
    this.m_jcodebar.setBackground(Color.white);
    this.m_jcodebar.setHorizontalAlignment(4);
    this.m_jcodebar.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)), BorderFactory.createEmptyBorder(1, 1, 1, 1)));
    this.m_jcodebar.setOpaque(true);
    this.m_jcodebar.setPreferredSize(new Dimension(135, 30));
    this.m_jcodebar.setRequestFocusEnabled(false);
    this.m_jcodebar.addMouseListener(new MouseAdapter()
    {
      public void mouseClicked(MouseEvent paramMouseEvent)
      {
        StockManagement.this.m_jcodebarMouseClicked(paramMouseEvent);
      }
    });
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 0;
    this.jPanel4.add(this.m_jcodebar, localGridBagConstraints);
    this.jTextField1.setBackground(UIManager.getDefaults().getColor("Panel.background"));
    this.jTextField1.setForeground(UIManager.getDefaults().getColor("Panel.background"));
    this.jTextField1.setCaretColor(UIManager.getDefaults().getColor("Panel.background"));
    this.jTextField1.setPreferredSize(new Dimension(1, 1));
    this.jTextField1.addKeyListener(new KeyAdapter()
    {
      public void keyTyped(KeyEvent paramKeyEvent)
      {
        StockManagement.this.jTextField1KeyTyped(paramKeyEvent);
      }
    });
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 1;
    localGridBagConstraints.fill = 1;
    this.jPanel4.add(this.jTextField1, localGridBagConstraints);
    this.jPanel2.add(this.jPanel4);
    this.btnDownloadProducts.setText("ScanPal");
    this.btnDownloadProducts.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        StockManagement.this.btnDownloadProductsActionPerformed(paramActionEvent);
      }
    });
    this.jPanel6.add(this.btnDownloadProducts);
    this.jPanel2.add(this.jPanel6);
    this.jPanel1.add(this.jPanel2, "North");
    add(this.jPanel1, "East");
    this.jPanel3.setLayout(null);
    this.jLabel1.setText(AppLocal.getIntString("label.stockdate"));
    this.jPanel3.add(this.jLabel1);
    this.jLabel1.setBounds(10, 30, 150, 15);
    this.jPanel3.add(this.m_jdate);
    this.m_jdate.setBounds(160, 30, 200, 19);
    this.m_jbtndate.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/date.png")));
    this.m_jbtndate.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        StockManagement.this.m_jbtndateActionPerformed(paramActionEvent);
      }
    });
    this.jPanel3.add(this.m_jbtndate);
    this.m_jbtndate.setBounds(370, 30, 40, 26);
    this.jLabel2.setText(AppLocal.getIntString("label.stockreason"));
    this.jPanel3.add(this.jLabel2);
    this.jLabel2.setBounds(10, 60, 150, 15);
    this.m_jreason.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        StockManagement.this.m_jreasonActionPerformed(paramActionEvent);
      }
    });
    this.jPanel3.add(this.m_jreason);
    this.m_jreason.setBounds(160, 60, 200, 20);
    this.jLabel8.setText(AppLocal.getIntString("label.warehouse"));
    this.jPanel3.add(this.jLabel8);
    this.jLabel8.setBounds(10, 90, 150, 15);
    this.jPanel3.add(this.m_jLocation);
    this.m_jLocation.setBounds(160, 90, 200, 20);
    this.m_jDelete.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/locationbar_erase.png")));
    this.m_jDelete.setFocusPainted(false);
    this.m_jDelete.setFocusable(false);
    this.m_jDelete.setMargin(new Insets(8, 14, 8, 14));
    this.m_jDelete.setRequestFocusEnabled(false);
    this.m_jDelete.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        StockManagement.this.m_jDeleteActionPerformed(paramActionEvent);
      }
    });
    this.jPanel3.add(this.m_jDelete);
    this.m_jDelete.setBounds(430, 230, 56, 44);
    this.m_jUp.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1uparrow22.png")));
    this.m_jUp.setFocusPainted(false);
    this.m_jUp.setFocusable(false);
    this.m_jUp.setMargin(new Insets(8, 14, 8, 14));
    this.m_jUp.setRequestFocusEnabled(false);
    this.m_jUp.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        StockManagement.this.m_jUpActionPerformed(paramActionEvent);
      }
    });
    this.jPanel3.add(this.m_jUp);
    this.m_jUp.setBounds(430, 130, 56, 44);
    this.m_jDown.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1downarrow22.png")));
    this.m_jDown.setFocusPainted(false);
    this.m_jDown.setFocusable(false);
    this.m_jDown.setMargin(new Insets(8, 14, 8, 14));
    this.m_jDown.setRequestFocusEnabled(false);
    this.m_jDown.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        StockManagement.this.m_jDownActionPerformed(paramActionEvent);
      }
    });
    this.jPanel3.add(this.m_jDown);
    this.m_jDown.setBounds(430, 180, 56, 44);
    this.jPanel5.setLayout(new BorderLayout());
    this.jPanel3.add(this.jPanel5);
    this.jPanel5.setBounds(10, 130, 410, 190);
    this.jPanel3.add(this.m_jLocationDes);
    this.m_jLocationDes.setBounds(370, 90, 200, 20);
    this.jEditAttributes.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/colorize.png")));
    this.jEditAttributes.setFocusPainted(false);
    this.jEditAttributes.setFocusable(false);
    this.jEditAttributes.setMargin(new Insets(8, 14, 8, 14));
    this.jEditAttributes.setRequestFocusEnabled(false);
    this.jEditAttributes.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        StockManagement.this.jEditAttributesActionPerformed(paramActionEvent);
      }
    });
    this.jPanel3.add(this.jEditAttributes);
    this.jEditAttributes.setBounds(430, 280, 58, 46);
    add(this.jPanel3, "Center");
    this.catcontainer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.catcontainer.setLayout(new BorderLayout());
    add(this.catcontainer, "South");
  }

  private void btnDownloadProductsActionPerformed(ActionEvent paramActionEvent)
  {
    DeviceScanner localDeviceScanner = this.m_App.getDeviceScanner();
    try
    {
      localDeviceScanner.connectDevice();
      localDeviceScanner.startDownloadProduct();
      for (ProductDownloaded localProductDownloaded = localDeviceScanner.recieveProduct(); localProductDownloaded != null; localProductDownloaded = localDeviceScanner.recieveProduct())
        incProductByCode(localProductDownloaded.getCode(), localProductDownloaded.getQuantity());
    }
    catch (DeviceScannerException localDeviceScannerException)
    {
      MessageInf localMessageInf = new MessageInf(-33554432, AppLocal.getIntString("message.scannerfail2"), localDeviceScannerException);
      localMessageInf.show(this);
    }
    finally
    {
      localDeviceScanner.disconnectDevice();
    }
  }

  private void m_jreasonActionPerformed(ActionEvent paramActionEvent)
  {
    this.m_jLocationDes.setEnabled(this.m_ReasonModel.getSelectedItem() == MovementReason.OUT_CROSSING);
  }

  private void m_jDownActionPerformed(ActionEvent paramActionEvent)
  {
    this.m_invlines.goDown();
  }

  private void m_jUpActionPerformed(ActionEvent paramActionEvent)
  {
    this.m_invlines.goUp();
  }

  private void m_jDeleteActionPerformed(ActionEvent paramActionEvent)
  {
    deleteLine(this.m_invlines.getSelectedRow());
  }

  private void m_jEnterActionPerformed(ActionEvent paramActionEvent)
  {
    incProductByCode(this.m_jcodebar.getText());
    this.m_jcodebar.setText(null);
  }

  private void m_jbtndateActionPerformed(ActionEvent paramActionEvent)
  {
    Date localDate;
	try
    {
      localDate = (Date)Formats.TIMESTAMP.parseValue(this.m_jdate.getText());
    }
    catch (BasicException localBasicException)
    {
      localDate = null;
    }
      localDate = JCalendarDialog.showCalendarTime(this, localDate);
    if (localDate != null)
      this.m_jdate.setText(Formats.TIMESTAMP.formatValue(localDate));
  }

  private void jNumberKeysKeyPerformed(JNumberEvent paramJNumberEvent)
  {
    stateTransition(paramJNumberEvent.getKey());
  }

  private void jTextField1KeyTyped(KeyEvent paramKeyEvent)
  {
    this.jTextField1.setText(null);
    stateTransition(paramKeyEvent.getKeyChar());
  }

  private void m_jcodebarMouseClicked(MouseEvent paramMouseEvent)
  {
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        StockManagement.this.jTextField1.requestFocus();
      }
    });
  }

  private void jEditAttributesActionPerformed(ActionEvent paramActionEvent)
  {
    int i = this.m_invlines.getSelectedRow();
    if (i < 0)
      Toolkit.getDefaultToolkit().beep();
    else
      try
      {
        InventoryLine localInventoryLine = this.m_invlines.getLine(i);
        JProductAttEdit localObject = JProductAttEdit.getAttributesEditor(this, this.m_App.getSession());
        ((JProductAttEdit)localObject).editAttributes(localInventoryLine.getProductAttSetId(), localInventoryLine.getProductAttSetInstId());
        ((JProductAttEdit)localObject).setVisible(true);
        if (((JProductAttEdit)localObject).isOK())
        {
          localInventoryLine.setProductAttSetInstId(((JProductAttEdit)localObject).getAttributeSetInst());
          localInventoryLine.setProductAttSetInstDesc(((JProductAttEdit)localObject).getAttributeSetInstDescription());
          this.m_invlines.setLine(i, localInventoryLine);
        }
      }
      catch (BasicException localBasicException)
      {
        Object localObject = new MessageInf(-33554432, AppLocal.getIntString("message.cannotfindattributes"), localBasicException);
        ((MessageInf)localObject).show(this);
      }
  }

  private class CatalogListener
    implements ActionListener
  {
    private CatalogListener()
    {
    }

    public void actionPerformed(ActionEvent paramActionEvent)
    {
      String str = StockManagement.this.m_jcodebar.getText();
      if (str != null)
      {
        Double localDouble = Double.valueOf(Double.valueOf(str).doubleValue() == 0.0D ? 1.0D : Double.valueOf(str).doubleValue());
        StockManagement.this.incProduct((ProductInfoExt)paramActionEvent.getSource(), localDouble.doubleValue());
        StockManagement.this.m_jcodebar.setText(null);
      }
      else
      {
        StockManagement.this.incProduct((ProductInfoExt)paramActionEvent.getSource(), 1.0D);
      }
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.inventory.StockManagement
 * JD-Core Version:    0.6.0
 */